jclass={
    initPage:function(){
        // 绑定dom对象
        this.obj = {
            searchText:$('#searchText'),
        };
        // 声明全局变量
        this.data = {
            datatable:[],
            tableParams: {
                platformName: '',
                accessCode: '',
                page:1,
                size:10
            }
        };
        this.getTableList();
        // this.creatTable();
        this.init();
        this.bindEvent();
    },
    init() {
        jrequest.get("/api/command-problem",{}).then(res => {
            // let options = ''
            // res.data.forEach(item => {
            //     options += `<option value=${item.id}>${item.informationProblem}</option>`
            // })
            // $("#cgin_select").html(options)
            res.data.forEach(item => {
                item.name = item.informationProblem
                item.val = item.id
            })
            jdSelect.JdSelectRadioInit('#dselect_cgxx',res.data,(select) => {
                
            })
        })
    },
    setCheck() {
        this.data.zTree = $.fn.zTree.getZTreeObj("treeDemo");
        this.data.zTree.setting.check.chkboxType = {Y: "s", N: "s"};
    },
    bindEvent() {
        $("#resetClick").click(() => {
            $("#search_input_jrm").val("")
            $("#search_input_platfrom").val("")

            this.data.tableParams = {
                platformName: '',
                accessCode: '',
                page:1,
                size:10
            }
        })
        $("#searchClick").click(() => {
            this.data.tableParams.page = 1;
            this.data.tableParams.size = 10;
            this.getTableList()
        })
    },
    getTableList() {
        $("#jid_loading").show()
        this.data.tableParams.platformName = $("#search_input_platfrom").val()
        this.data.tableParams.accessCode = $("#search_input_jrm").val()
        jrequest.get("/api/platforms/getAll",this.data.tableParams).then(res => {
            this.data.datatable = res.data
            $("#jtable_subplatform").bootstrapTable('destroy');
            this.creatTable(res)
            $("#jid_loading").hide()
            // $("#jtable_subplatform").bootstrapTable('load',res.data);
        })
    },
    tableEvent:function(id,data,columns,paginationShow,total){
        let that = this
        $('#' + id).bootstrapTable({
            method: 'get',
            cache: false,
            height: 320,
            pagination: paginationShow,
            pageSize: that.data.tableParams.size,
            pageNumber:that.data.tableParams.page,
            showColumns: true,
            striped: true,
            columns: columns,
            sidePagination: 'server', // client or server
            totalRows: total,
            data :data,
            onPageChange: function (size, number) {
                console.log(number)
                that.data.tableParams.page = number
                that.data.tableParams.size = size
                that.getTableList()
            },
            formatNoMatches: function(){
                return '暂无数据';
            }
        });
    },
    creatTable:function(res){
        var self=this;
        var columnsOne = [
            {
                title : '序号',
                align: "center",
                formatter: function (value, row, index) {
                    //获取每页显示的数量
                    var pageSize=self.data.tableParams.size;
                    //获取当前是第几页
                    var pageNumber=self.data.tableParams.page;
                    //返回序号，注意index是从0开始的，所以要加上1
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },
            {
              field: "name",
              title: "平台名称",
              visible: true
            },
            {
              field: "accessCode",
              title: "接入码",
              visible: true
            },
            {
              field: "linkStatus",
              title: "主链路状态",
              visible: true
            },
            {
              field: "onlineNum",
              title: "在线车辆数",
              visible: true
            },
            {
              field: "offlineNum",
              title: "离线车辆数",
              visible: true
            }
        ];
        self.tableEvent("jtable_subplatform",res.data,columnsOne,true,res.total);
    }
}


$(function(){
    jclass.initPage();
});


















